class Solution {
public:
    int maximumScore(vector<int>& nums, int k) {
        int n = nums.size(), ans = nums[k];
        int minnum = nums[k], left = k, right = k;
        for (int t = 0; t < n - 1; t++) {
            if (right == n - 1 || left && nums[left - 1] > nums[right + 1]) {
                minnum = min(nums[--left], minnum);

            } else {
                minnum = min(nums[++right], minnum);
            }
            ans = max(ans, minnum * (right - left + 1));
        }
        return ans;
    }
};